package org.ko.core.domain.auth;

import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.ko.core.domain.support.BaseEntity;

import com.fasterxml.jackson.annotation.JsonIgnore;


/**
 * 
 * @author ByTheWay
 *	系统菜单和动作表
 */
@Entity
@Table(name="SYS_MENU")
public class Menu extends BaseEntity{
	private static final long serialVersionUID = 601381011567970862L;
	private Menu parent;
	private List<Menu> children;
	
	private String name;
	private String url;
	private String icon;
	private Integer type; //0:菜单,1:动作
	private String remarks;
	private Integer orderNo;

	public Menu(Long id) {
		this.setId(id);
	}
	public Menu() {
	}
	@Column(length = 32,unique=true,nullable=false)
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	@Column(length = 255)
	public String getRemarks() {
		return remarks;
	}
	public void setRemarks(String remarks) {
		this.remarks = remarks;
	}
	@Column(length = 128)
	public String getUrl() {
		return url;
	}
	public void setUrl(String url) {
		this.url = url;
	}
	@Column(length = 96)
	public String getIcon() {
		return icon;
	}
	public void setIcon(String icon) {
		this.icon = icon;
	}
	
	@Column(nullable=false)
	public Integer getType() {
		return type;
	}
	public void setType(Integer type) {
		this.type = type;
	}
	
	@Column(nullable=false)
	public Integer getOrderNo() {
		return orderNo;
	}
	
	public void setOrderNo(Integer orderNo) {
		this.orderNo = orderNo;
	}
	
	@JsonIgnore
	@OneToMany(fetch = FetchType.LAZY,mappedBy = "parent")
//	@OrderBy("orderNum desc,id")
	public List<Menu> getChildren() {
		return children;
	}
	public void setChildren(List<Menu> children) {
		this.children = children;
	}
	
	@JsonIgnore
	@ManyToOne(fetch = FetchType.LAZY,optional=true)
	@JoinColumn(name = "pid")
	public Menu getParent() {
		return parent;
	}
	public void setParent(Menu parent) {
		this.parent = parent;
	}
	
	
}
